{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<style>
	.xian{
		width: 50px;text-align: center;height: 20px;line-height: 20px;margin-right: 10px;margin-top: 8px;
	}
	.xian_one{
		border: 1px solid #16baaa;color: #16baaa;
	}
</style>
<div class="p-3">
	<form class="layui-form gg-form-bar border-t border-x">
		<div class="layui-card-body">
			<div class="layui-collapse like-layui-collapse" lay-accordion="" style="border:1px dashed #c4c4c4">
				<div class="layui-colla-item">
					<h2 class="layui-colla-title like-layui-colla-title" style="background-color: #fff">筛选条件</h2>
<!--					<div class="layui-colla-content layui-show">-->
					<div class="layui-colla-content ">
						<div class="layui-form-item">
							<div class="layui-block">
								<label class="layui-form-label">所在地区</label>
								<div class="layui-input-block" style="display: flex">
									<div class="xian xian_one">不限</div>
									<select name="province_id" lay-filter="province" id="province">
										<option value="">选择省份</option>
										{volist name="$cityList" id="vo"}
										<option value="{$vo.id}">{$vo.name}</option>
										{/volist}
									</select>
									<select name="city_id" lay-filter="city" id="city">
										<option value="">选择城市</option>
									</select>
									<select name="district_id" lay-filter="district" id="district">
										<option value="">请选择县区</option>
									</select>
								</div>
							</div>
							<div class="layui-block" style="margin-top: 10px">
								<label class="layui-form-label">所属行业</label>
								<div class="layui-input-block" style="display: flex">
									<div class="xian xian_one">不限</div>
									<select name="cate_one" id="cate_one" lay-filter="selCate" lay-reqText="请选择一级分类">
										<option value="">请选择一级分类</option>
										{volist name="cate" id="v4"}
										<option value="{$v4.id}">{$v4.title}</option>
										{/volist}
									</select>
									<select name="cate_two" id="cate_two" lay-reqText="请选择二级分类">
										<option value="">请选择二级分类</option>
									</select>
								</div>
							</div>
							<div class="layui-block" style="margin-top: 10px">
								<label class="layui-form-label">营业状态</label>
								<div class="layui-input-block" style="display: flex">
									<div class="xian xian_one" id="bx_one">不限</div>
									<input type="checkbox" lay-filter="duo_one" name="yingye_id" value="在营/存续" title="在营/存续" >
									<input type="checkbox" lay-filter="duo_one" name="yingye_id" value="迁入/迁出" title="迁入/迁出" >
									<input type="checkbox" lay-filter="duo_one" name="yingye_id" value="吊销/撤销" title="吊销/撤销" >
									<input type="checkbox" lay-filter="duo_one" name="yingye_id" value="注销" title="注销" >
									<input type="checkbox" lay-filter="duo_one" name="yingye_id" value="停业" title="停业" >
									<input type="checkbox" lay-filter="duo_one" name="yingye_id" value="其他" title="其他" >
								</div>
							</div>
							<div class="layui-block" style="margin-top: 10px">
								<label class="layui-form-label">联系方式</label>
								<div class="layui-input-block" style="display: flex">
									<div class="xian xian_one" id="bx_two">不限</div>
									<input type="checkbox" lay-filter="duo_two" name="lianxi" value="有手机" title="有手机" >
									<input type="checkbox" lay-filter="duo_two" name="lianxi" value="有固话" title="有固话" >
									<input type="checkbox" lay-filter="duo_two" name="lianxi" value="有邮箱" title="有邮箱" >
									<input type="checkbox" lay-filter="duo_two" name="lianxi" value="有QQ" title="有QQ" >
									<input type="checkbox" lay-filter="duo_two" name="lianxi" value="无联系方式" title="无联系方式" >
								</div>
							</div>
							<div class="layui-block" style="margin-top: 10px">
								<label class="layui-form-label">成立年限</label>
								<div class="layui-input-block" style="display: flex">
									<div class="xian xian_one" id="bx_three">不限</div>
									<input type="checkbox" lay-filter="duo_three" name="riqi_year" value="1年以内" title="1年以内" >
									<input type="checkbox" lay-filter="duo_three" name="riqi_year" value="1-5" title="1-5年" >
									<input type="checkbox" lay-filter="duo_three" name="riqi_year" value="5-10" title="5-10年" >
									<input type="checkbox" lay-filter="duo_three" name="riqi_year" value="10-15" title="10-15年" >
									<input type="checkbox" lay-filter="duo_three" name="riqi_year" value="15年以上" title="15年以上" >
								</div>
							</div>
							<div class="layui-block" style="margin-top: 10px">
								<label class="layui-form-label">注册资本</label>
								<div class="layui-input-block" style="display: flex">
									<div class="xian xian_one" id="bx_four">不限</div>
									<input type="checkbox" lay-filter="duo_four" name="zhuce" value="20万以下" title="20万以下" >
									<input type="checkbox" lay-filter="duo_four" name="zhuce" value="20~50" title="20~50万" >
									<input type="checkbox" lay-filter="duo_four" name="zhuce" value="50~100" title="50~100万" >
									<input type="checkbox" lay-filter="duo_four" name="zhuce" value="100~200" title="100~200万" >
									<input type="checkbox" lay-filter="duo_four" name="zhuce" value="200~500" title="200~500万" >
									<input type="checkbox" lay-filter="duo_four" name="zhuce" value="500万以上" title="500万以上" >
								</div>
							</div>
							<div class="layui-block" style="margin-top: 10px">
								<label class="layui-form-label">高级筛选</label>
								<div class="layui-input-block" style="display: flex">
									<select name="leixing">
										<option value="">企业类型</option>
										<option value="">不限</option>
										{volist name="$qiCate" id="v5"}
										<option value="{$v5.title}">{$v5.title}</option>
										{/volist}
									</select>
									<select name="canbao">
										<option value="">参保人数</option>
										<option value="">不限</option>
										<option value="小于20人">小于20人</option>
										<option value="10~15人">10~15人</option>
									</select>
									<select name="zhaopin">
										<option value="">招聘情况</option>
										<option value="">不限</option>
										<option value="有招聘情况">有招聘情况</option>
										<option value="无招聘情况">无招聘情况</option>
									</select>
									<select name="wangluo">
										<option value="">网站推广</option>
										<option value="">不限</option>
										<option value="有网络推广">有网络推广</option>
										<option value="无网络推广">无网络推广</option>
									</select>
									<select name="yuming">
										<option value="">网站域名</option>
										<option value="">不限</option>
										<option value="有域名">有域名</option>
										<option value="无域名">无域名</option>
									</select>
								</div>
							</div>
							<div class="layui-block" style="margin-top: 10px">
								<label class="layui-form-label"></label>
								<div class="layui-input-block" style="display: flex">
									<select name="shangbiao">
										<option value="">商标</option>
										<option value="">不限</option>
										<option value="有商标">有商标</option>
										<option value="无商标">无商标</option>
									</select>
									<select name="zhuanli">
										<option value="">专利</option>
										<option value="">不限</option>
										<option value="有专利">有专利</option>
										<option value="无专利">无专利</option>
									</select>
									<select name="zhaobiao">
										<option value="">招投标</option>
										<option value="">不限</option>
										<option value="有招投标">有招投标</option>
										<option value="无招投标">无招投标</option>
									</select>
									<select name="gongzhong">
										<option value="">公众号</option>
										<option value="">不限</option>
										<option value="有公众号">有公众号</option>
										<option value="无公众号">无公众号</option>
									</select>
									<select name="news_file_id">
										<option value="">SVIP定制分类</option>
										{volist name="$svipCate" id="vv1"}
										<option value="{$vv1.id}">{$vv1.title}</option>
										{/volist}
									</select>
									<button style="margin-left: 5px" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<!--			<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>-->

	</form>
	<table class="layui-hide" id="news" lay-filter="news"></table>
</div>
{empty name="$uid"}
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加企业信息">+ 添加企业信息</span>
		<button type="button" class="layui-btn layui-btn-sm layui-bg-cyan jj"><i class="layui-icon"></i>导入数据</button>
		<a class="layui-btn layui-btn-sm layui-btn-normal" href="/static/assets/demo.xlsx">下载导入示例文件</a>
		<span class="layui-btn layui-btn-danger layui-btn-sm" lay-event="dels" data-title="批量删除">批量删除</span>
	</div>
</script>
{/empty}
<div class="row col-sm-12" style="display:none;" id="show_div">
	<form class="layui-form model-form" lay-filter="submitForm2" style="margin-top: 20px">
		<div class="layui-form-item">
			<div class="layui-block">
				<label class="layui-form-label">SVIP定制分类(可选项)：</label>
				<div class="layui-input-block">
					<select name="svip_cate_id" id="svip_cate_id">
						<option value="">选择分类</option>
						{volist name="$svipCate" id="vv"}
						<option value="{$vv.id}">{$vv.title}</option>
						{/volist}
					</select>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">导入方式：</label>
				<div class="layui-input-block">
					<input type="radio" name="dr_type" value="1" title="纯导入模式" checked>
					<input type="radio" name="dr_type" value="2" title="导入并覆盖">
					<input type="radio" name="dr_type" value="3" title="导入并更新">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">文件：</label>
				<div class="layui-input-inline">
					<input type="hidden" id="filepath" value="">
					<button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
					<span id="msg"></span>
				</div>
			</div>
		</div>
		<div class="layui-form-item" style="margin-left: 97px">
			<div class="layui-inline">
				<button class="layui-btn">确认</button>
			</div>
		</div>
	</form>
</div>
<script type="text/html" id="barDemo">
<div class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></div>
</script>
<script type="text/html" id="image">
	<img src="{{d.image}}" width="30" height="30" lay-event="image"/>
</script>
<script type="text/html" id="imagesArr">
	{{# if(d.images != ''){ }}
	{{# layui.each(d.images, function(index, item){ }}
	<img src="{{item}}" width="30" height="30"  lay-event="image"/>
	{{# }); }}
	{{# }else{}}
	暂无图片
	{{#}}}
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var table = layui.table,tool = layui.tool,upload = layui.upload, form = layui.form;
		upload.render({
			elem: '#test3'
			,url: '/admin/news/uploadFile' //此处配置你自己的上传接口即可
			,accept: 'file' //普通文件
			,done: function(res){
				$('#msg').html(res.msg)
				if (!res.code) {
					$('#filepath').val(res.data.filePath)
				}
			}
		});
		layui.pageTable = table.render({
			elem: '#news',
			title: '企业信息列表',
			toolbar: '#toolbarDemo',
			url: '/admin/news/datalists?uid={$uid}',
			page: true,
			limit: 20,
			// lineStyle:'height:auto',
			cellMinWidth: 60,
			cols: [
				[
					{type: 'checkbox', fixed: 'left'},
				{
					// fixed: 'left',
					field: 'id',
					title: '编号',
					align: 'center',
					width: 80
				},{
					field: 'news_file_name',
					title: 'SVIP定制分类',
					align: 'center',
					width: 160,
				},{
                        field: 'name',
                        title: '企业名称',
                        align: 'center',
                        width: 280,
                    },{
                        field: 'status',
                        title: '登记状态',
                        align: 'center',
						width: 100,
                    },{
                        field: 'faren',
                        title: '法定代表人',
                        align: 'center',
						width: 150,
                    },{
                        field: 'riqi',
                        title: '成立日期',
                        align: 'center',
						width: 150,
                    },{
                        field: 'riqi_year',
                        title: '成立年限',
                        align: 'center',
						width: 150,
                    },{
                        field: 'province',
                        title: '省份',
                        align: 'center',
						width: 150,
                    },{
                        field: 'city',
                        title: '市',
                        align: 'center',
						width: 150,
                    },{
                        field: 'district',
                        title: '区/县',
                        align: 'center',
						width: 150,
                    },{
                        field: 'address',
                        title: '注册地址',
                        align: 'center',
						width: 150,
                    },{
					field: 'lng',
					title: '经纬度',
					align: 'center',
					width: 150,
				},{
                        field: 'daima',
                        title: '统一社会信用代码',
                        align: 'center',
						width: 150,
                    },{
						field: 'mobile',
						title: '有效手机号',
						align: 'center',
						width: 100,
					},{
                        field: 'mobile_more',
                        title: '更多电话',
                        align: 'center',
						width: 150,
                    },{
                        field: 'leixing',
                        title: '企业类型',
                        align: 'center',
						width: 150,
                    },{
                        field: 'canbao',
                        title: '参保人数',
                        align: 'center',
						width: 100,
                    },{
                        field: 'zhaopin',
                        title: '招聘情况',
                        align: 'center',
						width: 100,
                    },{
                        field: 'wangluo',
                        title: '网络推广',
                        align: 'center',
						width: 100,
                    },{
                        field: 'yuming',
                        title: '网站域名',
                        align: 'center',
						width: 100,
                    },{
                        field: 'shangbiao',
                        title: '商标',
                        align: 'center',
						width: 100,
                    },{
                        field: 'zhuanli',
                        title: '专利',
                        align: 'center',
						width: 100,
                    },{
                        field: 'zhaobiao',
                        title: '招投标',
                        align: 'center',
						width: 100,
                    },{
                        field: 'gongzhong',
                        title: '公众号',
                        align: 'center',
						width: 100,
                    },{
                        field: 'emails',
                        title: '邮箱',
                        align: 'center',
						width: 100,
                    },{
                        field: 'qq',
                        title: 'qq号码',
                        align: 'center',
						width: 100,
                    },{
                        field: 'zhuce',
                        title: '注册资本',
                        align: 'center',
						width: 100,
                    },{
					field: 'jingying',
					title: '经营范围',
					align: 'center',
					width: 130,
				},{
                        field: 'cate_name',
                        title: '行业分类',
                        align: 'center',
						width: 100,
                    },{
                        field: 'create_time',
                        title: '创建时间',
                        align: 'center',
						width: 150,
                    },
				{
					field: 'right',
					fixed: 'right',
					title: '操作',
					toolbar: '#barDemo',
					width: 136,
					align: 'center'
				}				
				]
			]
		});

		$(document).on('click','.jj',function(){
			var index = layer.open({
				type: 1,
				title: ['导入文件'],//数组第二项可以写任意css样式；如果你不想显示标题栏，你可以title: false
				area: ['550px','350px'],
				content: $('#show_div'),
				success:function(){
					form.on('submit(submitForm2)', function (data) {
						var dr_type = $('input[name=dr_type]:checked').val();
						var filepath = $('#filepath').val();
						var svip_cate_id = $('#svip_cate_id').val();
						if (filepath === '') {
							layer.msg('请上传文件');
							return false
						}
						layer.load();
						$.post('/admin/news/btnImport', {filepath:filepath,dr_type:dr_type,svip_cate_id:svip_cate_id}, function(res) {
							layer.closeAll();
							layer.msg(res.msg,{icon:1,time:1500},function(){
								window.location.reload();
							});
						},'json');
						return false;
					});
				}
			})
		});
		//监听营业状态
		form.on('checkbox(duo_one)',function(data){
			var selectedValues = $('input[name="yingye_id"]:checked').map(function() {
				return this.value;
			}).get(); // 使用get()将jQuery对象转换为普通数组
			if (selectedValues.length>0) {
				$('#bx_one').removeClass('xian_one');
			} else {
				$('#bx_one').addClass('xian_one');
			}
		});
		//监听联系方式
		form.on('checkbox(duo_two)',function(data){
			var selectedValues = $('input[name="lianxi"]:checked').map(function() {
				return this.value;
			}).get(); // 使用get()将jQuery对象转换为普通数组
			if (selectedValues.length>0) {
				$('#bx_two').removeClass('xian_one');
			} else {
				$('#bx_two').addClass('xian_one');
			}
		});
		//监听成立年限
		form.on('checkbox(duo_three)',function(data){
			var selectedValues = $('input[name="riqi_year"]:checked').map(function() {
				return this.value;
			}).get(); // 使用get()将jQuery对象转换为普通数组
			if (selectedValues.length>0) {
				$('#bx_three').removeClass('xian_one');
			} else {
				$('#bx_three').addClass('xian_one');
			}
		});
		//监听注册资本
		form.on('checkbox(duo_four)',function(data){
			var selectedValues = $('input[name="zhuce"]:checked').map(function() {
				return this.value;
			}).get(); // 使用get()将jQuery对象转换为普通数组
			if (selectedValues.length>0) {
				$('#bx_four').removeClass('xian_one');
			} else {
				$('#bx_four').addClass('xian_one');
			}
		});

		//监听行业分类
		form.on('select(selCate)',function(data){
			let cate_id = data.value
			if (cate_id) {
				$('#cate_one').prev().removeClass('xian_one');
			} else {
				$('#cate_one').prev().addClass('xian_one');
			}
			tool.get("/admin/news/getCate", {id:cate_id}, function(res){
				let data = res.data
				let _html = '<option value="">请选择二级分类</option>';
				if (data.length > 0) {
					for (var i=0;i<data.length;i++) {
						_html += '<option value="'+data[i].id+'">'+data[i].title+'</option>';
					}
				}
				$('#cate_two').html(_html);
				form.render();
			});
		});

		//监听省份
		form.on('select(province)',function(data){
			let cate_id = data.value
			if (cate_id) {
				$('#province').prev().removeClass('xian_one');
			} else {
				$('#province').prev().addClass('xian_one');
			}
			$.ajax({
				url:'{:url("news/getcity")}',
				data:{id:cate_id},
				type:"get",
				success:function(res) {
					console.log(res)
					let data = res.data.data
					let _html = '<option value="">请选择城市</option>';
					if (data.length > 0) {
						for (var i=0;i<data.length;i++) {
							_html += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
						}
					}
					$('#city').html(_html);
					let _htmls = '<option value="">请选择县区</option>';
					$('#district').html(_htmls);
					form.render();
				}
			});
		});

		//监听市
		form.on('select(city)',function(data){
			let cate_id = data.value
			$.ajax({
				url:'{:url("news/getdis")}',
				data:{id:cate_id},
				type:"get",
				success:function(res) {
					let data = res.data.data
					let _html = '<option value="">请选择县区</option>';
					if (data.length > 0) {
						for (var i=0;i<data.length;i++) {
							_html += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
						}
					}
					$('#district').html(_html);
					form.render();
				}
			});
		});
		
		//监听表头工具栏事件
		table.on('toolbar(news)', function(obj){
			if (obj.event === 'add') {
				tool.side("/admin/news/add");
				return false;
			}
			if (obj.event === 'dels') {
				var news_arr = layui.table.checkStatus('news').data; // 获取选中行数据
				if (news_arr.length <= 0) {
					layer.msg('请选择要删除的数据');return false
				}
				var ids = [];
				for (var i=0;i<news_arr.length;i++) {
					ids.push(news_arr[i].id);
				}
				layer.confirm('确定要删除这些记录吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					$.post('/admin/news/dels', {ids:ids}, function(res) {
						layer.closeAll();
						if (res.code == 0) {
							layer.msg(res.msg,{icon:1,time:1500},function(){
								window.location.reload();
							});
						} else {
							layer.msg(res.msg,{icon:2,time:1500});
						}

					},'json');
					return false;
				});
			}
		});

		//监听表格行工具事件
		table.on('tool(news)', function(obj) {
			var data = obj.data;
			if (obj.event === 'read') {
				tool.side('/admin/news/read?id='+obj.data.id);
			}
			else if (obj.event === 'edit') {
				tool.side('/admin/news/edit?id='+obj.data.id);
			}
			else if (obj.event === 'del') {
				layer.confirm('确定要删除该记录吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/admin/news/del", { id: data.id }, callback);
					layer.close(index);
				});
			}
			if(obj.event === 'image')
			{
				var src = $(this).attr('src');
				// 在此处输入 layer 的任意代码
				layer.open({
					type: 1, // page 层类型
					area: ['500px', '500px'],
					title: '',
					shade: 0.6, // 遮罩透明度
					shadeClose: true, // 点击遮罩区域，关闭弹层
					maxmin: true, // 允许全屏最小化
					anim: 0, // 0-6 的动画形式，-1 不开启
					content: "<img src="+src+" style='width: 100%;'>"
				});
			}
			return false;
		});

		//监听搜索提交
		form.on('submit(searchform)', function(data) {
			// 使用serializeArray()获取数组
			var yingye_id = $('input[name="yingye_id"]:checked').serializeArray();
			var yingye_ids = $.map(yingye_id, function(item) {
				return item.value;
			});
			var lianxi = $('input[name="lianxi"]:checked').serializeArray();
			var lianxis = $.map(lianxi, function(item) {
				return item.value;
			});
			var riqi_year = $('input[name="riqi_year"]:checked').serializeArray();
			var riqi_years = $.map(riqi_year, function(item) {
				return item.value;
			});
			var zhuce = $('input[name="zhuce"]:checked').serializeArray();
			var zhuces = $.map(zhuce, function(item) {
				return item.value;
			});
			layui.pageTable.reload({
				where: {
					province_id: data.field.province_id,
					city_id: data.field.city_id,
					district_id: data.field.district_id,
					cate_one: data.field.cate_one,
					cate_two: data.field.cate_two,
					yingye_id: yingye_ids,
					lianxi: lianxis,
					riqi_year: riqi_years,
					zhuce: zhuces,
					leixing: data.field.leixing,
					canbao: data.field.canbao,
					zhaopin: data.field.zhaopin,
					wangluo: data.field.wangluo,
					yuming: data.field.yuming,
					shangbiao: data.field.shangbiao,
					zhuanli: data.field.zhuanli,
					zhaobiao: data.field.zhaobiao,
					gongzhong: data.field.gongzhong,
					news_file_id: data.field.news_file_id,
				},
				page: {
					curr: 1
				}
			});
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->